package cn.tedu.ivos2.user.controller;

import cn.tedu.ivos2.base.response.JsonResult;
import cn.tedu.ivos2.user.pojo.dto.UserLoginParam;
import cn.tedu.ivos2.user.pojo.dto.UserQuery;
import cn.tedu.ivos2.user.pojo.vo.UserVO;
import cn.tedu.ivos2.user.service.UserService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Tag(name = "用户模块")
@RestController
@RequestMapping("/v1/user")
public class UserController {
    @Autowired
    UserService userService;

    @PostMapping("/login")
    @Operation(summary = "用户登录")
    @ApiOperationSupport(order = 10)
    public JsonResult login(@Validated @RequestBody UserLoginParam userLoginParam){
        log.debug("用户登录:userLoginParam={}",userLoginParam);
        UserVO userVO = userService.login(userLoginParam);
        return JsonResult.ok(userVO);
    }

    @GetMapping("/select")
    @Operation(summary = "查询用户")
    @ApiOperationSupport(order = 20)
    public JsonResult select(UserQuery userQuery){
        log.debug("查询用户:{}",userQuery);
        List<UserVO> list = userService.selectUser(userQuery);
        return JsonResult.ok(list);
    }

}
